<div class="btn-group">
    <a class='btn btn-primary'> 贷款申请 </a>
</div>
    <form action="<?php echo site_url('loans/search'); ?>" method="GET" class="form-horizontal">
        <div class="control-group">
            <select name="type" id="status" class="bselect" data-size="auto" data-live-search="true" style="display: none;">
                <option value="">全部</option>
                <option value="99" <?php if(isset($_GET['type']) && $_GET['type']==99):?>selected="selected"<?php endif;?>>非产品贷款</option>
                <option value="1" <?php if(isset($_GET['type']) && $_GET['type']==1):?>selected="selected"<?php endif;?>>产品贷款</option>
            </select>
            <select name="status" id="status" class="bselect" data-size="auto" data-live-search="true" style="display: none;">
                <option value="">全部</option>
                <option value="99" <?php if(isset($_GET['status']) && $_GET['status']==99):?>selected="selected"<?php endif;?>>未处理</option>
                <option value="1" <?php if(isset($_GET['status']) && $_GET['status']==1):?>selected="selected"<?php endif;?>>无意向</option>
                <option value="2" <?php if(isset($_GET['status']) && $_GET['status']==2):?>selected="selected"<?php endif;?>>有意向</option>
            </select>
            <input class="btn-primary btn" type="submit" value="检索">
        </div>
</form>
<div class="clearfix"><p></p></div>
</form>

<?php include_once 'inc_ui_limit.php'; ?>

<div class="clearfix"></div>
<p></p>
<div class="boxed">
    <div class="boxed-inner seamless">
        <table class="table table-striped table-hover select-list">
            <thead>
            <tr>
                <th class="width-small"><input id='selectbox-all' type="checkbox" > </th>
                <th>姓名</th>
                <th>性别</th>
                <th>联系电话</th>
                <th>贷款类型</th>
                <th>产品名称</th>
                <th>贷款金额</th>
                <th>贷款期限</th>
                <th>联系地址</th>
                <th>状态</th>
                <th>时间</th>
            </tr>
            </thead>
            <tbody class="sort-list">
            <?php foreach ($list as $v):?>
                <tr data-id="<?php echo $v['id'] ?>" >
                    <td><input class="select-it" type="checkbox" value="<?php echo $v['id']; ?>" ></td>
                    <td> <?php echo $v['name'] ?> </td>

                    <td> <?php switch($v['sex']){case 1:echo '男';break;case 2: echo '女';break;default: echo "";break;} ?> </td>
                    <td> <?php echo $v['phone'] ?> </td>
                    <td> <?php echo $v['type']==1?'产品贷款申请':"非产品贷款申请" ?> </td>
                    <td> <?php echo $v['product_name'] ?> </td>
                    <td> <?php echo $v['price'] ?> </td>
                    <td> <?php echo  !empty($v['deadline'])?$v['deadline'].'月':''; ?> </td>
                    <td> <?php echo $v['address'] ?> </td>
                    <td> <?php switch($v['status']){case 0:echo '未处理';break;case 1: echo '无意向';break;case 2: echo '有意向';break;default: echo "未处理";break;} ?> </td>
                    <td> <?php echo  date("Y/m/d H:i:s",$v['timeline']); ?> </td>
                    <td style="text-align:right;">
                        <div class="btn-group">
                            <?php if ($v['status']==0): ?>
                                <a href="javascript:void(0);"   class='btn btn-primary btn-small btn-ajax-cancel' data-id="<?php echo $v['id'] ?>" data-cancel="0" data-status="<?php echo $v['status']; ?>">未处理</a>
                            <?php else: ?>
                                <a href="javascript:void(0);"  class='btn btn-small btn-ajax-cancel' data-id="<?php echo $v['id'] ?>" data-cancel="0" data-status="<?php echo $v['status']; ?>">未处理</a>
                            <?php endif; ?>
                            <?php if ($v['status']==1): ?>
                                <a href="javascript:void(0);"  class='btn btn-primary btn-small btn-ajax-cancel' data-id="<?php echo $v['id'] ?>" data-cancel="1" data-status="<?php echo $v['status']; ?>">无意向</a>
                            <?php else: ?>
                                <a href="javascript:void(0);" class='btn btn-small btn-ajax-cancel' data-id="<?php echo $v['id'] ?>" data-cancel="1" data-status="<?php echo $v['status']; ?>">无意向</a>
                            <?php endif; ?>
                            <?php if ($v['status']==2): ?>
                                <a href="javascript:void(0);"   class='btn btn-primary btn-small btn-ajax-cancel' data-id="<?php echo $v['id'] ?>" data-cancel="2" data-status="<?php echo $v['status']; ?>">有意向</a>
                            <?php else: ?>
                                <a href="javascript:void(0);" class='btn btn-small btn-ajax-cancel' data-id="<?php echo $v['id'] ?>" data-cancel="2" data-status="<?php echo $v['status']; ?>">有意向</a>
                            <?php endif; ?>
                            <a class='btn btn-danger btn-small btn-del' href="#" data-id="<?php echo $v['id'] ?>" title=" <?php echo lang('del') ?>"> <i class="fa fa-times"></i></a>
                        </div>
                    </td>
                </tr>
            <?php endforeach;?>
            </tbody>
        </table>
    </div>
</div>

<div class="btn-group">
    <a id='select-all' class='btn' href="#"> <i class=""></i> <?php echo lang('select_all') ?> </a>
    <a id='unselect-all' class='btn hide' href="#"> <i class=""></i> <?php echo lang('unselect') ?> </a>
    <a id="btn-del" class='btn btn-danger' href="#"> <i class="fa fa-times"></i> <?php echo lang('del') ?> </a>
</div>

<?php echo $pages; ?>

<script>
    require(['adminer/js/ui','bootstrap-datetimepicker.zh'],function(ui){
        $('.timepicker').datetimepicker({'language':'zh-CN','format':'yyyy/mm/dd hh:ii:ss','todayHighlight':true});
        loans = {
            url_del: "<?php echo site_url('loans/delete'); ?>"
            ,url_sortid: "<?php echo site_url('loans/sortid'); ?>"
            ,url_audit: "<?php echo site_url('loans/audit'); ?>"
        };

        ui.btn_delete(loans.url_del);		// 删除
        ui.sortable(loans.url_sortid);	// 排序
        ui.btn_audit(loans.url_audit);// 审核
        $(".select-list").delegate('.btn-ajax-cancel', 'click', function(event) {
            if($(this).data('cancel')!='undefined'){
                event.preventDefault();
                var audit = {
                    id:$(this).attr('data-id'),
                    audit:$(this).attr('data-cancel'),
                    it:$(this),
                    i:$(this).children('i')
                };
                $.ajax({
                        url: loans.url_audit,
                        type: 'POST',
                        dataType: 'json',
                        data: {
                            ids:audit.id,
                            audit:audit.audit,
                            _cfs:$.cookie('_cfc')
                        }
                    })
                    .done(function(data) {
                        var msg = {
                            title:'',
                            text:data.msg,
                            type:'',
                            delay:3000
                        };
                        if (data.status == 1 ) {
                            msg.title = "OK!";
                            msg.type = 'success';
                            audit.it.addClass('btn-primary');
                            audit.it.next().removeClass('btn-primary');
                            audit.it.next().next().removeClass('btn-primary');
                            audit.it.attr('data-status',data.audit);
                            window.location.reload();

                            //msg.type = 'notice';
                        }else{
                            msg.title = "错误！";
                            msg.type = 'error';
                        }
                        $.pnotify(msg);
                    })
                    .fail(function(XMLHttpRequest, textStatus, errorThrown){
                        var m = XMLHttpRequest.responseJSON;
                        $.pnotify({
                            title:"错误提示！",
                            text:m.msg,
                            type:"error",
                            animation: 'fade'
                        });
                    })
                    .always(function() {
                        console.log("complete");
                    });
            }


        });
    });
</script>
